﻿define([
    '../libs/zepto',
    '../common/base',
    '../common/dialog',
    '../common/common_click',
    '../common/ajax',
	'../find/defaultJSON'],function(){
    this.init = function(){
        setCss();
        _isOnlineFQA();
        var _appEName ='';
        myscroll.refresh();
        
    }

    function setCss(){
    	$('.onlineBox').css('display','block');
    	$('.ulbox').css('display','block');
    	$('.erweimaBox').css('display','block');
    	$('.loading').css('display','block');
    	_appEName = G_Cookie.getAppEName();
        var whole_height = window.innerHeight;
        var head_height = $('.header').height();
        var foot_height = $('.footer').height();
        var head2_height = $('.onlineBox').height();
        
        
        var icon_width = $('.icon').width();
        var whole_width = window.innerWidth;
        $('#wrapper').css('height',whole_height-head_height-foot_height-head2_height)
//      $('.ulbox').css('height',whole_height-head_height-foot_height-head2_height)
        
        $('.list').css('width',whole_width*0.93-icon_width)
//      $('.find-content').css('height',whole_height-head_height-foot_height);
        $('.wechat').css('display','block');
        
        if(_appEName in defaultJson.videoAppEnameArr){//显示视频课程按钮
        	$('.list1').css('display','block')//考试指南
        	$('.list2').css('display','block')//资讯站
        	$('.list3').css('display','block')//产品站
        	$('.list4').css('display','block')//视频课程
        	
        	
		}
//      else if (_appEName in defaultJson.zsbk_appENameArr) {//知识宝库考点梳理
//          //显示考点梳理
//          $('.list1').css('display','none')
//      	$('.list2').css('display','block')
//      	$('.list3').css('display','block')
//      	$('.list4').css('display','block')
//
//      }
        else if(_appEName in defaultJson.videoAppEnameArr && _appEName in defaultJson.zsbk_appENameArr){
        	$('.list1').css('display','block')
        	$('.list2').css('display','block')
        	$('.list3').css('display','block')
        	$('.list4').css('display','block')
        }else {
        	$('.list1').css('display','block')
        	$('.list2').css('display','block')
        	$('.list3').css('display','block')
        	$('.list3 .list').css('border-bottom','none')
        	$('.list4').css('display','none')
        }
	
        $('.list1').on('click',function(){
            window.location.href = '/find/examGuide';
        });
        $('.list4').on('click',function(){
            window.location.href = '/videoList';
        });
        //资讯站=========================================================
        $('.list2').on('click',function(){
            //浏览器类型
            function _getClientType() {
                if(navigator.userAgent.indexOf("MicroMessenger") !== -1) {
                    return 'web_messenger';
                } else if(navigator.userAgent.indexOf("Windows Phone") !== -1) {
                    return 'web_winphone';
                } else if(navigator.userAgent.indexOf("iPhone") !== -1) {
                    return 'web_iphone';
                } else if(navigator.userAgent.indexOf("Android") !== -1) {
                    return 'web_android';
                } else {
                    return 'web_pc';
                }
            }
            //安卓==========================================================
            if(_getClientType() == "web_android"){
		
                window.android.information('a');
            } else if(_getClientType() == "web_iphone" || "ipad" || "iphone") {
            	//iOS======================================================
                
               parent.window.location.href = 'ioszx://asd';
            }
        });
        
        $('.list3').click(function(){
        	//浏览器类型
            function _getClientType() {
                if(navigator.userAgent.indexOf("MicroMessenger") !== -1) {
                    return 'web_messenger';
                } else if(navigator.userAgent.indexOf("Windows Phone") !== -1) {
                    return 'web_winphone';
                } else if(navigator.userAgent.indexOf("iPhone") !== -1) {
                    return 'web_iphone';
                } else if(navigator.userAgent.indexOf("Android") !== -1) {
                    return 'web_android';
                } else {
                    return 'web_pc';
                }
            }
            //安卓==========================================================
            if(_getClientType() == "web_android") {
                window.android.product('b');
            } else if(_getClientType() == "web_iphone" || "ipad" || "iphone") {
            //iOS======================================================
               parent.window.location.href = 'ioscp2://asd';
            }
        });

        $('.erweima img').on('click',function(){
            //浏览器类型
            function _getClientType() {
                if(navigator.userAgent.indexOf("MicroMessenger") !== -1) {
                    return 'web_messenger';
                } else if(navigator.userAgent.indexOf("Windows Phone") !== -1) {
                    return 'web_winphone';
                } else if(navigator.userAgent.indexOf("iPhone") !== -1) {
                    return 'web_iphone';
                } else if(navigator.userAgent.indexOf("Android") !== -1) {
                    return 'web_android';
                } else {
                    return 'web_pc';
                }
            }
            if(_getClientType() == "web_android") {
            	//安卓保存图片
                window.android.showErweima('c');
            } else if(_getClientType() == "web_iphone" || "ipad" || "iphone") {
            	parent.window.location.href = 'ioserweima://ios.cn';
            }
        })
       
    }
    /********************************************************************************
	 函数名：_isOnlineFQA
	 功能：判断是否有在线答疑
	 输入参数：无
	 返回值：无
	 *******************************************************************************/
	function _isOnlineFQA() {
		var appID = G_Cookie.getAppID();
		if (!appID) {
			G_Prg.throw('程序运行错误，defaultPage._isOnlineFQA ,不能处理appID=' + appID);
		}
		var URL = '/api/app/getAppInfo?appID=' + appID;
		var success = function (json) {
			var jsonData = JSON.parse(json);
			if (jsonData.status === 200) {
				var isHasFQA = jsonData.data.hasOnlineSolve;
				$('.intoOnline').on('click',function(){
					if(isHasFQA === 1){
						window.location.href = '/onlineFAQ?fromUrl=find';
					}else{
						G_Prg.alert('功能正在筹备中~')
					}
					
				})
				
			} else if (jsonData.status === 201) {
	
			} else {
			}
		};
		G_AjaxApi_Record.get(URL, true, success);
	}

    init();
});